package com.iam.api.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.iam.api.model.Sign;
import com.iam.api.service.SignService;
import com.iam.api.service.SysUserService;
import com.iam.core.model.SysUser;
import com.iam.core.service.AbstractBaseCommonService;
import com.iam.core.service.ISysUserService;
import com.iam.api.mapper.SignMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 */
@Service
public class SignServiceImpl extends AbstractBaseCommonService<SignMapper, Sign> implements SignService<Sign> {

    @Autowired
    private SysUserService<SysUser> userService;

    @Override
    public boolean save(Sign entity) {
        SysUser currentUser = userService.getById(StpUtil.getLoginIdAsInt());
        entity.setCode(generate11DigitId());
        entity.setCreatorName(currentUser.getUserName());
        return super.save(entity);
    }

    public static String generate11DigitId() {
        // 获取13位时间戳（毫秒级）
        String a = new SimpleDateFormat("yyyyMMddhhmmss").format(
                new Date()).toString();
        // 转换为11位：取后11位或截取前11位
        String id = a.substring(0, 11);
        return id;
    }
}




